#include "FiveWin.ch"

static oPrinter

//----------------------------------------------------------------------------//

CLASS TPrinter

   DATA   hDC

   METHOD New( cDocument, oWnd ) CONSTRUCTOR
   METHOD StartPage() BLOCK { | Self | StartPage( ::hDC ) }
   METHOD EndPage()   BLOCK { | Self | EndPage( ::hDC ) }
   METHOD End()       BLOCK { | Self | EndDoc( ::hDC ), DeleteDC( ::hDC ) }
   METHOD Say( nRow, nCol, cText, oFont )
   METHOD SetPos( nRow, nCol )                     VIRTUAL
   METHOD Line( nRow, nCol )                       VIRTUAL
   METHOD Rectangle( nRow, nCol, nWidth, nHeight ) VIRTUAL

ENDCLASS

//----------------------------------------------------------------------------//

METHOD New( cDocument, oWnd ) CLASS TPrinter

   ::hDC = GetPrintDC( If( oWnd == nil, GetActiveWindow(), oWnd:hWnd ) )

   StartDoc( ::hDC, cDocument )

return

//----------------------------------------------------------------------------//

METHOD Say( nRow, nCol, cText, oFont ) CLASS TPrinter

   if oFont != nil
      oFont:Activate( ::hDC )
   endif

   TextOut( ::hDC, nRow, nCol, cText )

   if oFont != nil
      oFont:DeActivate( ::hDC )
   endif

return

//----------------------------------------------------------------------------//

// Algunas funciones amigas                    // Friend functions

function PrintBegin( cDocName )

return ( oPrinter := TPrinter():New( cDocName ) )

//----------------------------------------------------------------------------//

function PageBegin() ; oPrinter:StartPage() ; return

function PageEnd() ; oPrinter:EndPage(); return

function PrintEnd() ; oPrinter:End() ; oPrinter := nil; return

//----------------------------------------------------------------------------//
